package com.yuuzy.qqserver.service;

import com.yuuzy.qqcommon.Message;

import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 该类用于管理和客户端通信的线程
 */
public class ManageClientThreads {
	private static HashMap<String,ServerConnectClientThread> hm = new HashMap<>();

	//添加线程对象到 hm 集合
	public static void addClientThread(String userID,ServerConnectClientThread serverConnectClientThread){
		hm.put(userID,serverConnectClientThread);
	}

	//根据userID返回一个线程
	public static ServerConnectClientThread getServerConnectClientThread(String userID){
		return hm.get(userID);
	}
	//根据userID移除一个线程
	public static void removeServerConnectClientThread(String userID){
		hm.remove(userID);
	}
	//这里编写方法，可以返回在线用户列表
	public static String getOnlineUsers(){
		Iterator<String> iterator = hm.keySet().iterator();
		String users = "";
		while (iterator.hasNext()){
			users += iterator.next() + " ";
		}
		return users;
	}

	//获取当前的线程数量
	public static int getLiveNumber(){
		return hm.size();
	}


}
